package com.hp.attendance.dao;

import com.hp.attendance.entity.Leave;
import com.hp.attendance.entity.Menu;
import com.hp.attendance.util.BaseDAO;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class LeaveDao extends BaseDAO {
    /**
     * 请假记录查询
     * @return
     */
    public List<Leave> getList() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        String sql ="select * from lea";
        List<Leave> list = queryList(sql, new Object[0], new Leave());
        return list;
    }

    /**
     * 根据员工编号查询出所对应员工姓名
     * @param empNumber
     * @return
     */
    public List<Leave> getLeaveByNumber(int empNumber) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        String sql="select * from employee e " +
                " left join lea l on e.employee_number = l.employee_number" +
                " where l.`employee_number`=?";
        Object[] obj ={empNumber};
        List<Leave> leave = queryList(sql, obj, new Leave());
        return  leave;
    }

    /**
     * 根据审核状态获取请假表
     * @return
     */
    public List<Leave> getLeaveByStatus(String leaveStatus) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        String sql = "select * from lea where status=?";
        Object[] obj ={leaveStatus};
        List<Leave> leave = queryList(sql, obj, new Leave());
        return leave;
    }

    /**
     * 根据Id获取Leave对象
     * @param id
     */
    public Leave getLeaveQueryOne(int id) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        String sql = "select * from lea where id=?";
        Object[] obj = {id};
        Leave leave = queryOne(sql, obj, new Leave());
        return leave;
    }

    /**
     * 审批和驳回
     * @param status
     * @param id
     */
    public void updateLeave(String status ,int id) throws SQLException, IOException, ClassNotFoundException {
        String sql ="update lea set status=? where id=?";
        Object[] obj={status,id};
        addOrUpdOrDel(sql,obj);
    }
}
